{include file='pub/header'/}
<title>App启动图管理</title>
</head>
<body>
<nav class="breadcrumb">{$breadNav} <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                       href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a class="btn btn-primary radius" onclick="category_add('添加广告','{:url(\'Content/advAdd\')}')"
               href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加广告</a>
        </span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg table-hover table-sort">
            <thead>
            <tr class="text-c">
                <th width="40">ID</th>
                <th width="100">标题</th>
                <th width="100">图片</th>
                <th width="100">是否展示</th>
                <th width="150">操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $list as $item}
            <tr class="text-c">
                <td>{$item.id}</td>
                <td>
                    <p>{$item.title}</p>
                </td>
                <td>
                    <img src="{$item.image}" style="width: 120px; height: auto;" alt="">
                </td>
                <td>
                    {if $item.is_show eq 1}
                    <button onclick="changeStatus('{$item.id}', 0)" class="btn btn-primary size-MINI radius">是</button>
                    {else/}
                    <button onclick="changeStatus('{$item.id}', 1)" class="btn btn-default size-MINI radius">否</button>
                    {/if}
                </td>
                <td class="td-manage">
                    <a style="text-decoration:none" class="ml-5" onClick="category_edit('编辑消息', '{:url(\'Content/advAdd\', [\'id\'=>$item.id])}')"
                       href="javascript:;"><i class="Hui-iconfont Hui-iconfont-edit"></i>编辑</a>
                    <a style="text-decoration:none" class="ml-5" onClick="category_del(this,'{$item.id}')"
                       href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i>删除</a>
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
        {$list->render()}
    </div>
</div>

{include file="pub/footer"/}
<script type="text/javascript">

    function changeStatus(id, status) {
        $.post('{:url("changeIndexStatus")}', {id:id, is_show:status}, function (res) {
            if(res.code == 1){
                location.reload();
            }else{
                layer.msg(res.msg);
            }
        });
    }

    /*分类-添加*/
    function category_add(title, url) {
        var index = layer.open({
            type: 2,
            title: title,
            area: ['600px', '450px'],
            content: url
        });
        layer.full(index);
    }


    /*分类-编辑*/
    function category_edit(title, url, id) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url,
            area: ['600px', '450px']
        });
        layer.full(index);
    }

    /*分类-删除*/
    function category_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: '{:url("Content/delAdv")}',
                data: {id: id},
                dataType: 'json',
                success: function (data) {
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!', {icon: 1, time: 1000});
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }
</script>
</body>
</html>